package day3.demo10_lock方法;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Sell implements Runnable{
    int sum = 1000;
    Lock lo = new ReentrantLock();
    @Override
    public void run() {
        while (sum>0){
            sell();
        }
    }
    void sell(){
        try {
            lo.lock();
            if (sum <= 0) {
                return;
            }
            System.out.println(Thread.currentThread().getName() + "卖出第" + sum + "张票");
            sum--;
        }finally {
            lo.unlock();
        }
    }
}
